﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using Texfina.Core.Common;
using Texfina.Core.Web;
using Texfina.Common.Mg;
using Texfina.Common.Rh;
using Texfina.Core.Data;
using Texfina.Entity.Rh;
using Texfina.Entity.Mg;
using RHBOQry = Texfina.BOQry.Rh;
using MGBOQry = Texfina.BOQry.Mg;

namespace RH
{
   public partial class wfVarCalculoBnd : SearchPage
   {
      public const int _GRDLIST_IDESTADO = 5;

      protected void Page_Load(object sender, EventArgs e)
      {

         this.LoadInitialSettings();
         if (this.IsPostBack)
         {
            this.LoadInPostBack();
            return;
         }

         this.LoadData();
         SearchData();

      }

      public override void LoadInitialSettings()
      {
         Label lbl = (Label)this.Master.FindControl("lblTitle");
         lbl.Text = "Variables de Calculo";
         this.Page.Form.DefaultButton = bttSearch.UniqueID;
      }

      public override void LoadListControls()
      {

         ETablaGenDet objEDet = new ETablaGenDet();
         MGBOQry.ITablaGen objBOI = (MGBOQry.ITablaGen)WCFHelper.GetObject<MGBOQry.ITablaGen>(typeof(MGBOQry.TablaGen));

         objEDet.IdTabla = ConstMultitabla.TIPO_CONCEPTO_PLANILLA;
         DataTable dt = objBOI.GetDetailByList(objEDet);
         WebHelper.LoadListControl(ddlidTipoCampo, dt, "dsDescrip", "idCodigo", true, true);

      }
      public override void SearchData()
      {

         EVarCalc objE = new EVarCalc();

         if (this.txtidVarCalc.Text == "")
            objE.IdVarCalc = null;
         else
            objE.IdVarCalc = this.txtidVarCalc.Text;

         if (this.txtdsVarCalc.Text == "")
            objE.DsVarCalc = null;
         else
            objE.DsVarCalc = this.txtdsVarCalc.Text;

         if (this.ddlidTipoCampo.SelectedValue.ToString() == "")
            objE.IdTipo = null;
         else
            objE.IdTipo = this.ddlidTipoCampo.SelectedValue.ToString();

         IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.VarCalc));
         DataTable dt = objBO.GetByCriteria(objE);

         this.GridSetDataBinding(grdList, dt);

      }

      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
         String strQS = "";

         switch (e.Item.Value)
         {
            case ConstMenuToolbarValue.BUTTON_NEW:
               strQS = "wfVarCalculoMnt.aspx?formEA=" + Convert.ToInt32(FormEditAction.AddNew).ToString() + "&idVarCalc=&idTipo=" +
                  ConstTipoVariable.VARIABLE;
               break;
            case "_BTTNEWACU":
               strQS = "wfVarCalculoMnt.aspx?formEA=" + Convert.ToInt32(FormEditAction.AddNew).ToString() + "&idVarCalc=&idTipo=" +
                  ConstTipoVariable.ACUMULADOR;
               break;
         }
         Response.Redirect(strQS);
      }

      protected void grdList_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
         DataRow dr = this.GridGetRowFromDataKey(grdList, Convert.ToInt32(e.CommandArgument));
         FormEditAction formEA = FormEditAction.AddNew;

         switch (e.CommandName)
         {
            case ConstGridRowCommand.GRIDEDIT:
               formEA = FormEditAction.Edit;
               break;
            case ConstGridRowCommand.GRIDDELETE:
               formEA = FormEditAction.Delete;
               break;
            case ConstGridRowCommand.GRIDPREVIEW:
               //this.PrintReport(Convert.ToInt32(e.CommandArgument));
               return;
         }
         String strQS = "wfVarCalculoMnt.aspx?formEA=" + Convert.ToInt32(formEA).ToString() + "&idVarCalc=" + dr["idVarCalc"].ToString() +
            "&idTipo=" + dr["idTipo"].ToString();
         Response.Redirect(strQS);

      }

      protected void bttOk_Click(object sender, EventArgs e)
      {
         this.SearchData();
      }
   }
}